import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/home/detail/page/cook_detail_page.dart';
import 'package:flutter_douban/model/cook_info_model.dart';
import 'package:flutter_douban/tool_views/cached_network_Image.dart';

class AttentionView extends StatefulWidget {
  final CookInfoModel model;
  const AttentionView({Key? key, required this.model}) : super(key: key);

  @override
  _AttentionViewState createState() => _AttentionViewState();
}

class _AttentionViewState extends State<AttentionView> {
  @override
  Widget build(BuildContext context) {
    List<Widget> widgetList = [];
    widgetList.add(
      InkWell(
        child: CachedNetworkImage(
          imageUrl: widget.model.img!,
          fit: BoxFit.cover,
          width: MediaQuery.of(context).size.width,
        ),
        onTap: () {
          Navigator.of(context).push(MaterialPageRoute(builder: (_) {
            return CookDetailPage(id: widget.model.id!);
          }));
        },
      ),
    );

    if(widget.model.videoUrl?.isNotEmpty == true){
      /// 视频
      widgetList.add(
          Positioned(
            bottom: 5,
            right: 5,
            child: Image.asset(
              'assets/images/common/cell_video_play@2x.png',
              width: 32,
              height: 32,
            ),
          )
      );
    }

    return Container(
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.all(10),
            child: Row(
              children: [
                /// 头像
                IconImage(
                    url: widget.model.nickIcon!,
                    width: 32,
                    height: 32,
                    radius: 16,
                    borderWidth: 1,
                    borderColor: Colors.transparent),
                SizedBox(
                  width: 10,
                ),

                /// 昵称
                Text(
                  widget.model.nickName!,
                  style: TextStyle(color: AppColors.black),
                )
              ],
            ),
          ),
          Stack(
            children: widgetList,
          ),
          Container(
            alignment: Alignment.centerLeft,
            margin: EdgeInsets.all(10),
            child: Text(
              widget.model.n!,
              style: TextStyle(
                fontSize: 15,
                color: AppColors.deepTextColor,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
